/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminPointRouteInfo: {
                routes: [],
                inspectionId: '',
                inspectionRouteId:'',
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('adminPointRoute', 'switch', function (_data) {
                $that.adminPointRouteInfo.inspectionId = _data.inspectionId;
                $that.adminPointRouteInfo.inspectionRouteId = _data.inspectionRouteId;
                
                $that._loadAdminPointRouteData(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('adminPointRoute', 'paginationPlus', 'page_event',
                function (_currentPage) {
                    $that._loadAdminPointRouteData(_currentPage, DEFAULT_ROWS);
                });
            vc.on('adminPointRoute', 'notify', function (_data) {
                $that._loadAdminPointRouteData(DEFAULT_PAGE, DEFAULT_ROWS);
            })
        },
        methods: {
           
            _loadAdminPointRouteData: function (_page, _row) {
                let param = {
                    params: {
                        inspectionId: $that.adminPointRouteInfo.inspectionId,
                        inspectionRouteId:$that.adminPointRouteInfo.inspectionRouteId,
                        page: _page,
                        row: _row
                    }
                };
                //发送get请求
                vc.http.apiGet('/inspectionRoute.listAdminInspectionRoutes',
                    param,
                    function (json) {
                        let _json = JSON.parse(json);
                        $that.adminPointRouteInfo.routes = _json.inspectionRoutes;
                        if(_json.inspectionRoutes && _json.inspectionRoutes.length>0){
                            $that._switchAdminPointRoute(_json.inspectionRoutes[0]);
                        }
                    },
                    function () {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _qureyAdminPointRoute: function () {
                $that._loadAdminPointRouteData(DEFAULT_PAGE, DEFAULT_ROWS);
            },

            _switchAdminPointRoute:function(_route){
                $that.adminPointRouteInfo.inspectionRouteId = _route.inspectionRouteId;
                setTimeout(function(){
                    vc.emit('aInspectionRouteMap','initMap',{
                        inspectionRouteId:_route.inspectionRouteId
                    })
                },1000);
            },
            
            
        }
    });
})(window.vc);